<?php
/**
 * 发送语音短信
 * @author cj
 * @time 20200111
 */
namespace App\Libraries;
use Sms\SmsCommitSender;

require __DIR__ . '/../../vendor/Sms/index.php';

class SendVoice {


    public function __construct()
    {
    }

    /**
     * send
     */
    public function send($phoneNumbers,$content){

//        $url      = 'http://api.51welink.com/EncryptionSubmit/SendSms.ashx';//env('MESSAGE_URL'); //接口地址
        $account  = "dlbjlnd";//env('MESSAGE_ACCOUNT');//账号
        $password = '0kjfBliS';//env('MESSAGE_PASSWORD');//密码
//        $sign     = env('MESSAGE_SIGN');//签名
//        $conente  = '您的短信验证码是'.$number.' 如非本人操作，请忽略此短信。本短信免费。【'.$sign.'】';
//        $phoneNumbers = ["17343011172"];
//        $content = "1号大棚 土壤温度过高";

        try {
            $send = new SmsCommitSender($account, $password);
            $result = $send->send('', '1012838', $phoneNumbers, $content, '', '');
            echo $result;
        } catch (\Exception $e) {
            echo var_dump($e);
        }

//        $res = $this->post_data_curl($url, $data, 1);
//        return $res;
    }

    public function post_data_curl($url, $data, $isMulitArray = 0) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_TIMEOUT, 180);

        curl_setopt($ch, CURLOPT_POST, 1);
        if ($isMulitArray) {
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        } else {
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        }

        $output = curl_exec($ch);
        curl_close($ch);
        $output = json_decode($output, true);
        return $output;
    }


}